package first.codeTop.meituan;

/**
 * @ClassName Leetcode141
 * @description:
 * @author: 荣燊
 * @create: 2021-08-01 15:04
 **/
public class Leetcode141 {
    // 环形链表
    public static void main(String[] args) {

    }

    public static boolean hasCycle(ListNode head) {
        // 双指针
        if (head == null || head.next == null) {
            return false;
        }
        ListNode slow = head;
        ListNode quick = head.next;
        while (slow != quick) {
            if (quick == null || quick.next == null) {
                return false;
            }
            slow = slow.next;
            quick = quick.next.next;
        }
        return true;
    }

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
